<?php

namespace apiend\modules\shop\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\shop\models\ShopProductDetail;
use apiend\modules\shop\models\ShopGoodsDetail;
use common\models\shop\ShopAttachment;
use apiend\modules\shop\models\CheckSkuSearch;

/**
 * 商品相关接口
 * ProfileController for the `shop` module
 */
class GoodsController extends Controller {

    /**
     * Declares the allowed HTTP verbs.
     * Please refer to [[VerbFilter::actions]] on how to declare the allowed verbs.
     * @return array the allowed HTTP verbs.
     */
    protected function verbs() {
        return [
            '*' => ['GET']
        ];
    }

    /**
     * 商品规格选择查询
     * @return mixed
     */
    public function actionCheck() {
        $model = new CheckSkuSearch();
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    public function actionProduct() {
        $model = new ShopProductDetail();
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    public function actionGoods() {
        $model = new ShopGoodsDetail();
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    /**
     * @inheritdoc
     */
    public function actionView($id) {
        $albums = ShopAttachment::find()
        ->where(['product_id' => $id])
        ->orderBy(['listorder' => SORT_ASC])
        ->all();
        return compact('albums');
    }

}
